package org.zjh.view.register;

import org.zjh.controller.action.CancelJbtLis;
import org.zjh.controller.listener.RegisterPanelRegisterJbtLis;


import javax.swing.*;
import java.awt.*;

import static org.zjh.constant.ImageConstant.*;


/**
 * 注册面板
 */
public class RegisterPanel extends JPanel {

    private JTextField nicknameTextField;
    private JPasswordField passwordField;
    private JPasswordField okPasswordField;
    private JTextField securityIssuesTextField1;
    private JTextField securityIssuesTextField2;
    private JButton registerNowJbt;
    private JButton cancelJbt;
    private JTextField securityIssuesAnswerTextField1;
    private JTextField securityIssuesAnswerTextField2;


    public RegisterPanel() {
        init();
        addListener();
    }

    /**
     * 初始化
     */
    private void init() {
        setLayout(null);
        //创建标签
        JLabel nicknameLabel = new JLabel("昵称");
        JLabel passwordLabel = new JLabel("密码");
        JLabel okPasswordLabel = new JLabel("确认密码");
        JLabel securityIssuesLabel1 = new JLabel("设置密保问题一");
        JLabel securityIssuesLabel2 = new JLabel("设置密保问题二");
        JLabel securityIssuesAnswerLabel1 = new JLabel("答案");
        JLabel securityIssuesAnswerLabel2 = new JLabel("答案");

        //设置标签属性
        nicknameLabel.setBounds(450, 50, 100, 50);
        nicknameLabel.setFont(new Font("黑体", Font.PLAIN, 25));
        passwordLabel.setBounds(450, 125, 100, 50);
        passwordLabel.setFont(new Font("黑体", Font.PLAIN, 25));
        okPasswordLabel.setBounds(400, 200, 100, 50);
        okPasswordLabel.setFont(new Font("黑体", Font.PLAIN, 25));
        securityIssuesLabel1.setBounds(325, 275, 175, 25);
        securityIssuesLabel1.setFont(new Font("黑体", Font.PLAIN, 25));
        securityIssuesAnswerLabel1.setBounds(450, 350, 175, 25);
        securityIssuesAnswerLabel1.setFont(new Font("黑体", Font.PLAIN, 25));
        securityIssuesLabel2.setBounds(325, 425, 175, 25);
        securityIssuesLabel2.setFont(new Font("黑体", Font.PLAIN, 25));
        securityIssuesAnswerLabel2.setBounds(450, 500, 175, 25);
        securityIssuesAnswerLabel2.setFont(new Font("黑体", Font.PLAIN, 25));

        //字体颜色加粗
        nicknameLabel.setForeground(Color.BLACK);
        passwordLabel.setForeground(Color.BLACK);
        okPasswordLabel.setForeground(Color.BLACK);
        securityIssuesLabel1.setForeground(Color.BLACK);
        securityIssuesLabel2.setForeground(Color.BLACK);
        securityIssuesAnswerLabel1.setForeground(Color.BLACK);
        securityIssuesAnswerLabel2.setForeground(Color.BLACK);
        securityIssuesLabel2.setForeground(Color.BLACK);

        //创建文本框
        nicknameTextField = new JTextField();
        passwordField = new JPasswordField();
        okPasswordField = new JPasswordField();
        securityIssuesTextField1 = new JTextField();
        securityIssuesTextField2 = new JTextField();
        securityIssuesAnswerTextField1 = new JTextField();
        securityIssuesAnswerTextField2 = new JTextField();
        securityIssuesTextField2 = new JTextField();

        //设置属性
        nicknameTextField.setBounds(525, 60, 100, 25);
        passwordField.setBounds(525, 135, 100, 25);
        okPasswordField.setBounds(525, 210, 100, 25);
        securityIssuesTextField1.setBounds(525,275,100,25);
        securityIssuesAnswerTextField1.setBounds(525,350,100,25);
        securityIssuesTextField2.setBounds(525,425,100,25);
        securityIssuesAnswerTextField2.setBounds(525,500,100,25);

        //创建按钮
        registerNowJbt = new JButton(REGISTER_NOW_IMAGE);
        cancelJbt = new JButton(CANCEL_IMAGE);

        //按钮设置属性
        registerNowJbt.setBounds(400, 600, 150, 50);
        cancelJbt.setBounds(650, 600, 100, 50);

        //添加 标签 文本框 按钮
        add(nicknameLabel);
        add(passwordLabel);
        add(okPasswordLabel);
        add(securityIssuesLabel1);
        add(securityIssuesLabel2);
        add(securityIssuesAnswerLabel1);
        add(securityIssuesAnswerLabel2);
        add(nicknameTextField);
        add(passwordField);
        add(okPasswordField);
        add(securityIssuesTextField1);
        add(securityIssuesTextField2);
        add(securityIssuesAnswerTextField1);
        add(securityIssuesAnswerTextField2);
        add(registerNowJbt);
        add(cancelJbt);

    }

    /**
     * 添加监听器
     */
    private void addListener(){
        //给返回按钮设置动作指令
        cancelJbt.setActionCommand("registerCancel");
        //添加动作监听
        cancelJbt.addActionListener(CancelJbtLis.getInstance());
        registerNowJbt.addMouseListener(new RegisterPanelRegisterJbtLis());
    }

    /**
     * 刷新页面
     */
    public void refresh() {
        nicknameTextField.setText("");
        passwordField.setText("");
        okPasswordField.setText("");
        securityIssuesTextField1.setText("");
        securityIssuesTextField2.setText("");
        securityIssuesAnswerTextField1.setText("");
        securityIssuesAnswerTextField2.setText("");
    }




    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(REGISTER_IMAGE.getImage(), 0, 0, LOGIN_PANEL_IMAGE.getIconWidth(), LOGIN_PANEL_IMAGE.getIconHeight(), null);
    }


    public JTextField getNicknameTextField() {
        return nicknameTextField;
    }

    public JPasswordField getPasswordField() {
        return passwordField;
    }

    public JPasswordField getOkPasswordField() {
        return okPasswordField;
    }

    public JTextField getSecurityIssuesTextField1() {
        return securityIssuesTextField1;
    }

    public JTextField getSecurityIssuesTextField2() {
        return securityIssuesTextField2;
    }


    public JTextField getSecurityIssuesAnswerTextField1() {
        return securityIssuesAnswerTextField1;
    }

    public JTextField getSecurityIssuesAnswerTextField2() {
        return securityIssuesAnswerTextField2;
    }
}
